<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>AngelScript: Context manager</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>


</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">AngelScript
   
   </div>
   
  </td>
  
  
  
   
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('doc_addon_ctxmgr.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">Context manager </div>  </div>
</div>
<div class="contents">
<div class="textblock"><p><b>Path:</b> /sdk/add_on/contextmgr/</p>
<p>The <code>CContextMgr</code> is a class designed to aid the management of multiple simultaneous scripts executing in parallel. It supports both <a class="el" href="doc_adv_concurrent.html">concurrent script threads</a> and <a class="el" href="doc_adv_coroutine.html">co-routines</a>.</p>
<p>If the application doesn't need multiple contexts, i.e. all scripts that are executed always complete before the next script is executed, then this class is not necessary.</p>
<p>Multiple context managers can be used, for example when you have a group of scripts controlling ingame objects, and another group of scripts controlling GUI elements, then each of these groups may be managed by different context managers.</p>
<p>Observe, that the context manager class hasn't been designed for multithreading, so you need to be careful if your application needs to execute scripts from multiple threads.</p>
<dl class="see"><dt><b>See also:</b></dt><dd>The samples <a class="el" href="doc_samples_concurrent.html">Concurrent scripts</a> and <a class="el" href="doc_samples_corout.html">Co-routines</a> for uses</dd></dl>
<h2><a class="anchor" id="doc_addon_ctxmgr_1"></a>
Public C++ interface</h2>
<div class="fragment"><pre class="fragment"><span class="keyword">class </span>CContextMgr
{
<span class="keyword">public</span>:
  CContextMgr();
  ~CContextMgr();

  <span class="comment">// Set the function that the manager will use to obtain the time in milliseconds.</span>
  <span class="keywordtype">void</span> SetGetTimeCallback(TIMEFUNC_t func);

  <span class="comment">// Registers the script function</span>
  <span class="comment">//</span>
  <span class="comment">//  void sleep(uint milliseconds)</span>
  <span class="comment">//</span>
  <span class="comment">// The application must set the get time callback for this to work</span>
  <span class="keywordtype">void</span> RegisterThreadSupport(<a class="code" href="classas_i_script_engine.html" title="The engine interface.">asIScriptEngine</a> *engine);

  <span class="comment">// Registers the script functions</span>
  <span class="comment">//</span>
  <span class="comment">//  void createCoRoutine(const string &amp;in functionName, any @arg)</span>
  <span class="comment">//  void yield()</span>
  <span class="keywordtype">void</span> RegisterCoRoutineSupport(<a class="code" href="classas_i_script_engine.html" title="The engine interface.">asIScriptEngine</a> *engine);

  <span class="comment">// Create a new context, prepare it with the function id, then return </span>
  <span class="comment">// it so that the application can pass the argument values. The context</span>
  <span class="comment">// will be released by the manager after the execution has completed.</span>
  <a class="code" href="classas_i_script_context.html" title="The interface to the virtual machine.">asIScriptContext</a> *AddContext(<a class="code" href="classas_i_script_engine.html" title="The engine interface.">asIScriptEngine</a> *engine, <span class="keywordtype">int</span> funcId);

  <span class="comment">// Create a new context, prepare it with the function id, then return</span>
  <span class="comment">// it so that the application can pass the argument values. The context</span>
  <span class="comment">// will be added as a co-routine in the same thread as the currCtx.</span>
  <a class="code" href="classas_i_script_context.html" title="The interface to the virtual machine.">asIScriptContext</a> *AddContextForCoRoutine(<a class="code" href="classas_i_script_context.html" title="The interface to the virtual machine.">asIScriptContext</a> *currCtx, <span class="keywordtype">int</span> funcId);

  <span class="comment">// Execute each script that is not currently sleeping. The function returns after </span>
  <span class="comment">// each script has been executed once. The application should call this function</span>
  <span class="comment">// for each iteration of the message pump, or game loop, or whatever.</span>
  <span class="keywordtype">void</span> ExecuteScripts();

  <span class="comment">// Put a script to sleep for a while</span>
  <span class="keywordtype">void</span> SetSleeping(<a class="code" href="classas_i_script_context.html" title="The interface to the virtual machine.">asIScriptContext</a> *ctx, <a class="code" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815" title="32 bit unsigned integer">asUINT</a> milliSeconds);

  <span class="comment">// Switch the execution to the next co-routine in the group.</span>
  <span class="comment">// Returns true if the switch was successful.</span>
  <span class="keywordtype">void</span> NextCoRoutine();

  <span class="comment">// Abort all scripts</span>
  <span class="keywordtype">void</span> AbortAll();
};
</pre></div> </div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>

    <li class="footer">Generated on Sun Jan 29 2012 15:41:03 for AngelScript by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.5.1 </li>
   </ul>
 </div>


</body>
</html>
